package com.example.controller.admin;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.example.common.Result;
import com.example.dto.TagAddDTO;
import com.example.dto.TagDeleteDTO;
import com.example.dto.TagPageDTO;
import com.example.entity.Tag;
import com.example.service.TagService;
import com.example.vo.TagListVO;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 标签表 前端控制器
 * </p>
 *
 * @author wuyunbin
 * @since 2024-10-18
 */
@Slf4j
@RestController
@RequestMapping("/admin/tag")
public class TagController {

    @Resource
    private TagService tagService;

    @PostMapping("/add")
    public Result<Object> add(@RequestBody TagAddDTO tagAddDTO){
        tagService.saveBatch(tagAddDTO.getTags());
        return Result.success();
    }

    @PostMapping("/list")
    public Result<IPage<Tag>> list(@RequestBody TagPageDTO tagPageDTO){
        IPage<Tag> page=tagService.getPage(tagPageDTO);
        return Result.success(page);
    }

    @PostMapping("/delete")
    public Result<Object> delete(@RequestBody TagDeleteDTO tagDeleteDTO){
        tagService.removeById(tagDeleteDTO.getTagId());
        return Result.success();
    }

    @PostMapping("/select/list")
    public Result<List<TagListVO>> selectList(){
        List<TagListVO> tagListVOList = tagService.getSelectList();
        return Result.success(tagListVOList);
    }

}
